package com.zzq.my.jetpacks.jectpackapp

import android.view.LayoutInflater
import android.widget.LinearLayout
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.zzq.my.jetpacks.jectpackapp.adapter.RvAdapter
import com.zzq.my.jetpacks.jectpackapp.bean.ItemInfo
import com.zzq.my.jetpacks.jectpackapp.databinding.ActivityMainBinding
import com.zzq.my.jetpacks.jectpackapp.ui.act.*
import com.zzq.my.jetpacks.jectpackapp.ui.dzfs.ArrivalMethodAct
import com.zzq.my.jetpacks.jectpackapp.ui.dzfs.WithdrawAct
import com.zzq.my.jetpacks.jectpackapp.ui.scan.PlayLoadingAct
import com.zzq.my.jetpacks.jectpackapp.ui.scan.PlayStatusAct
import com.zzq.my.jetpacks.jectpackapp.ui.scan.PlayTickAct
import com.zzq.my.jetpacks.util.DividerItemUtils
import com.zzq.my.jetpacks.util.goActivity



/*
  * ================================================
  * 描述：封装Retrofit+协程，实现优雅快速的网络请求
  * 作者：zhuangzeqin
  * 时间: 2021/11/25-10:52
  * 邮箱：zzq@eeepay.cn
  * 备注:
  * ----------------------------------------------------------------
  * You never know what you can do until you try !
  *      _              _           _     _   ____  _             _ _
  *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
  *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
  *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
  *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
  *
  * 签名：最痛苦的事不是我失败了，而是我本可以.--zzq
  * ----------------------------------------------------------------
  * ================================================
  */

class MainActivity : BaseActivity(R.layout.activity_main) {
    //    private val mLoginViewModel by viewModels<LoginViewModel>()
//    private val mLoadIndexDataVM by viewModels<LoadIndexDataVM>()
//    private val adapter = MultiTypeAdapter()
//    private val items = ArrayList<Any>()
    private val mMainBindingView by viewBinding(ActivityMainBinding::bind)

    private lateinit var rvAdapter: RvAdapter

    /**
     * 初始化数据
     */
    override fun initData() {

    }

    /**
     * 初始化操作
     */
    override fun initView() {
        rvAdapter = RvAdapter()
        val mutableListOf = mutableListOf<ItemInfo>()
        val listOf = listOf(
            "网络请求封装",
            "ConcatAdapter合并多个rv适配器",
            "androidx Fragment 懒加载",
            "FlexboxLayout弹性布局",
            "Rxhttp 网络请求封装",
            "ShapeView阴影基本用法",
            "MMKV 的基本使用",
            "Flow 的基本是使用",
            "fresco 强大的图片加载框架",
            "APP 引导页",
            "fresco 强大的图片加载框架",
            "ActivityMessenger简化Activity之间传参和回调的逻辑代码。",
            "step指示器动态添加",
            "到账方式",
            "账号提现",
            " 实现带空格分隔的输入电话号码",
            " NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端",
            " ViewPager listView 滑动冲突解决",
            " Scrollview rv 滑动冲突解决",
            " HeaderScrollViewActivity 吸顶",
            " PlayLoadingAct 支付页面",
            " PlayStatusAct 支付状态页面",
            " PlayTickAct 签购小票",
            " BottomSheetActivity",
            " ShapeableImageViewActivity",
            " ViewPager2 轮播图",
            " GrowUpCenterAct 成长中心",
        )
        listOf.forEach {
            mutableListOf.add(ItemInfo(it))
        }
        rvAdapter.setList(mutableListOf)
        val noDataView =
            LayoutInflater.from(mContext)
                .inflate(R.layout.lib_res_layout_nodata_foot, null) //没有数据的
        rvAdapter.addFooterView(view = noDataView,orientation =  LinearLayout.HORIZONTAL)
        //添加自定义分割线：可自定义分割线高度和颜色
        mMainBindingView.rvList.addItemDecoration(
//            DividerItemUtils.dividerItemDecorationTool(mContext)//默认的间隔线
            DividerItemUtils.dividerItemDecorationTool(
                mContext,
                drawId = R.drawable.divider_mileage
            )//自定义间隔线
        )
        mMainBindingView.rvList.adapter = rvAdapter//适配器
    }

    /**
     * 初始化点击事件操作
     */
    override fun eventOnClick() {
        //::rvAdapter.isInitialized用于判断adapter是否已经初始化
        if (::rvAdapter.isInitialized) {
            rvAdapter.setOnItemClickListener { adapter, view, position ->
                val item = adapter.getItem(position) as ItemInfo
//                Logger.t("item").d(item.name)
                when (position) {
                    0 -> goActivity<HttpAct>(mContext)//todo  网络请求封装
                    1 -> goActivity<ConcatAdapterAct>(mContext)//todo 按顺序添加的适配器RV 的 adapter
                    2 -> goActivity<FragLazyAct>(mContext) //todo androidx Fragment 懒加载
                    3 -> goActivity<FlexboxLayoutAct>(mContext)
                    4 -> goActivity<RxHttpAct>(mContext)
                    5 -> goActivity<ShapeViewActivity>(mContext)
                    6 -> goActivity<MMKVActivity>(mContext)
                    7 -> goActivity<FlowActivity>(mContext)
                    8 -> goActivity<FrescoActivity>(mContext)
                    12 -> goActivity<Activity8>(mContext)
                    13 -> goActivity<ArrivalMethodAct>(mContext)
                    14 -> goActivity<WithdrawAct>(mContext)
                    15 -> goActivity<EdtiextAct>(mContext)
                    16 -> goActivity<Activity10>(mContext)
                    17 -> goActivity<Activity11>(mContext)
                    18 -> goActivity<Activity12>(mContext)
                    19 -> goActivity<HeaderScrollViewActivity>(mContext)
                    20 -> goActivity<PlayLoadingAct>(mContext)
                    21 -> goActivity<PlayStatusAct>(mContext)
                    22 -> goActivity<PlayTickAct>(mContext)
                    23 -> goActivity<BottomSheetActivity>(mContext)
                    24 -> goActivity<ShapeableImageViewActivity>(mContext)
                    25 -> goActivity<ViewPager2BannerAct>(mContext)
                    25 -> goActivity<GrowUpCenterAct>(mContext)
                }

            }
        }
    }
}